package com.scy.edu.controller;

import com.scy.edu.entity.Account;
import com.scy.edu.entity.DataConfig;
import com.scy.edu.service.AccountService;
import org.I0Itec.zkclient.ZkClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 司晨雨
 * @date 2020/10/11 21:02
 * @description
 */
@RestController
public class AccountController {

    @Autowired
    private AccountService accountService;


    @RequestMapping("/getAccountList")
    public String getAccountList(Model model) throws Exception {
        List<Account> accountList = accountService.getAllList();
        model.addAttribute("list", accountList);
        return "list";
    }

    @RequestMapping("/updateDataSource")
    public void update(){
        ZkClient zkClient = new ZkClient("127.0.0.1:2181");
        DataConfig dataConfig = new DataConfig();
        dataConfig.setDriverClass("com.mysql.jdbc.Driver");
        dataConfig.setUrl("jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8&useSSL=false");
        dataConfig.setUserName("root");
        dataConfig.setPassword("admin");
        zkClient.writeData("/dataSource", dataConfig);
    }
}
